import { NCheckboxGroup } from "naive-ui";
import type { CheckboxGroupProps } from "naive-ui";
import type { BaseComponentType, OmitHTMLAttributes } from "../types";
import { getSlotsDom } from "../utils";

export type CheckboxGroupFactoryConstructorType = {
  attrs?: OmitHTMLAttributes<"onChange">;
  props?: CheckboxGroupProps;
  defaultSlot?: BaseComponentType;
};
export class CheckboxGroupFactory {
  private attrs: OmitHTMLAttributes<"onChange"> = {};
  private props: CheckboxGroupProps = {};
  private defaultSlot: BaseComponentType = null;

  constructor(data?: CheckboxGroupFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: OmitHTMLAttributes<"onChange">) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: CheckboxGroupProps) {
    this.props = props;
    return this;
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  create() {
    return (
      <NCheckboxGroup {...this.props} {...this.attrs}>
        {{
          default: () => getSlotsDom(this.defaultSlot),
        }}
      </NCheckboxGroup>
    );
  }
}
